<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Shijue_weixin extends CI_Controller {
public function __construct() {
        parent::__construct();
    }

public function add_users(){
	$rs_weibo= $this->db->where('clue_type',3)->get('shijue_project_new');
        $data =$rs_weibo->result_array();
        //print_r($data);die;
        foreach ($data as $v) {
	        $res = $this->weibo_uid($v['clue_address']);
		$weibo_data['biz'] = $res;
	        echo $rs = $this->db->where('id',$v['id'])->update('shijue_project_new',$weibo_data);
	      
        }		

}
public function weibo_uid($url=''){
if(!$url){
    $e = array('code'=>400);
    $res = json_encode($e);
    print_r($res);
}
$url = trim($url);
$rs = strpos($url,"m.weibo");
if($rs){
    $str =substr($url,-10); 
    return $str;
}
$rs = $this->send_http(trim($url));
preg_match_all("|CONFIG\['oid'\]='(.*?)';|ims", $rs, $r);
$data= strip_tags($r[1][0]);
//print_r($data);
return $data;
}


function send_http($url, $post = array(), $ip = "", $timeout = 15, $header = array(), $connecttimeout = 15) {

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:50.0) Gecko/20100101 Firefox/50.0');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $connecttimeout);
    curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);

     $cookie = "SUB=_2A250_Ua0DeThGeBN4loV8SvJzzSIHXVXiz98rDV8PUNbmtBeLRPikW86-ey9AyJvjSMRjv0I0d-q8mNPKw..;";
    curl_setopt($ch, CURLOPT_COOKIE, $cookie);
    
    if($post){
        if(is_array($post)){
            $post = http_build_query($post);
        }

        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
    }

    if ($header){
        curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
    }
    
    if(!empty($ip)) {
        curl_setopt($ch, CURLOPT_PROXY, $ip);
        curl_setopt($ch, CURLOPT_PROXYTYPE , CURLPROXY_SOCKS5);
        curl_setopt($ch, CURLOPT_PROXYUSERPWD, "hongmai:soften.cn");
    }

    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    //curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1); 
    
    $rs = curl_exec($ch);
    $http_info = curl_getinfo($ch);
    //print_r($http_info);
    curl_close($ch);
    if($http_info['http_code'] != 200 && $http_info['http_code'] != 302 ){
        //print_r($http_info);
        return false;
    }
    return $rs;
}

}
